home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / STREAMS / STORAGE.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-15  |  2KB  |  61 lines

  1.  { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; storage of objects in streams
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBDEF, EFLIBINI, EFLIBDAT, EFLIBIO, EFLIBBAS;
  10.  
  11.  
  12. var MyStructure : TextObjectPointerType;
  13.     MyObject    : ObjectPointerType;
  14.     MyStream    : FileStreamObjectType;
  15.     Data        : string;
  16.  
  17. begin
  18.      { Initialize data structure (can be of any type that supports
  19.        stream storage) }
  20.      New (MyStructure, Initialize);
  21.  
  22.      with MyStructure^ do begin
  23.           Data := 'Stream storage makes it very easy to transfer objects'; Add (Data);
  24.           Data := 'to a file or to a memory allocation, and then reconstruct'; Add (Data);
  25.           Data := 'the entire object later.'; Add (Data);
  26.  
  27.           with MyStream do begin
  28.                Initialize ('TEMP.$$$', 1024); Create;
  29.                WriteLn ('* Stores object to stream *');
  30.                Store (MyStructure);
  31.                { Read object from stream }
  32.                Seek (0);
  33.                WriteLn ('* Loads object to stream *');
  34.                Load (MyObject);
  35.                Intercept; { Stream }
  36.           end;
  37.  
  38.           if MyObject^.IsInitialized and (MyStructure^.IsEqual(MyObject)) then
  39.              with StructureObjectPointerType(MyObject)^ do begin
  40.                   { Write the objects type name }
  41.                   WriteLn ('This object is of the type ', NameOfType, '.');
  42.                   WriteLn ('* Content *');
  43.                   { Construct an iterator for the data type }
  44.                   with CreateIterator^ do begin
  45.                        repeat
  46.                              { Display element contents }
  47.                              WriteLn (String(Content^));
  48.                              WalkForward; { Go to next element }
  49.                        until IsEnd;
  50.                        Free; { Iterator }
  51.                   end;
  52.                   Free; { My object }
  53.           end else WriteLn ('* Failed to reconstruct object! *');
  54.  
  55.           MyStructure^.Free;
  56.  
  57.           WriteLn ('* Done *');
  58.      end;
  59.  
  60.      DeleteFile ('TEMP.$$$'); { Delete temporary test file }
  61. end.